package com.example.zsr.downloadcontinue;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

import static android.content.ContentValues.TAG;

/**
 * Created by zhengshaorui on 2017/1/30.
 */

public class MyApplication extends Application{
    private static Context mContext;
    private static PackageManager mPackageManager;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        mPackageManager = mContext.getPackageManager();
    }

    public static Context getAppContext(){
        return mContext;
    }

    public static void startApplication(ComponentName componentName) {
        // TODO Auto-generated method stub
        try {
            mPackageManager.getActivityInfo(componentName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            Log.d(TAG, "startApplication the packagename:" + componentName.getPackageName() + " is error");
            e.printStackTrace();
        }
        Intent localIntent = new Intent("android.intent.action.MAIN");
        localIntent.addCategory("android.intent.category.LAUNCHER");
        localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        localIntent.setComponent(componentName);
        mContext.startActivity(localIntent);
    }
}
